package com.climber.android.lib_share.platform

import cn.sharesdk.framework.Platform
import com.climber.android.lib_share.sensor.MyAuthorizeActionListener
import com.climber.android.lib_share.sensor.AuthorizeResultCallBack

/**
 * Created by Mikes at 2020-03-20 10:03
 */
class PlatformAuthorizeDelegate(val platform : Platform, val builder: AuthorizeResultCallBack.Builder.() -> Unit) {
    fun doAuthorize() {
        if(platform.isAuthValid){
            platform.removeAccount(true)
        }
        //SSO授权，传false默认是客户端授权
        platform.SSOSetting(false)
        //授权回调监听，监听onComplete，onError，onCancel三种状态
        platform.platformActionListener = MyAuthorizeActionListener(builder)
        // 只获取授权信息，不获取用户信息
        platform.authorize()
    }

    fun doUserInfo() {
        if(platform.isAuthValid){
            // 移除授权状态和本地缓存，下次授权会重新授权
            platform.removeAccount(true)
        }
        //SSO授权，传false默认是客户端授权
        platform.SSOSetting(false)
        //授权回调监听，监听onComplete，onerror，oncancel三种状态
        platform.platformActionListener = MyAuthorizeActionListener(builder)
        //请求授权用户的资料
        platform.showUser(null)
    }
}